package com.just521.xinshoutong.listadapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.just521.xinshoutong.common.CommonDefine;



public class ListAdapter_base<T> extends BaseAdapter
{
	
	protected Context		mContext;			
	protected List<T> 			m_vec; 
	LayoutInflater mfactory;
	Resources mr;
	public ListAdapter_base(Context c,List<T> list )
	{
		mContext 	= c;
		m_vec		= list; 
		if(m_vec==null){
			m_vec=new ArrayList<T>();
		}
		mfactory = LayoutInflater.from(mContext);
		mr=CommonDefine.getResources(mContext);
	}
	public void UpdateList(List<T> list){
		m_vec=list;
		notifyDataSetChanged();
	}
	public View getHeader(HashMap<String,Object> header,ViewGroup parent){
		View retV=null;
//		try{
//			retV = mfactory.inflate(R.layout.bbs_listitem,parent, false);
//		}catch(InflateException e){
//		}
//		retV.setBackgroundColor(Color.argb(255, 230, 180, 80));
//		setContent(retV,header);
		return retV;
	}
	protected int isVip(long vipbeg,long vipend){
		int ret=0;
		long cur=System.currentTimeMillis();
		if(vipend>cur){
			double year = (double)((vipend - cur) / (1000*24*3600));
			
			long  y = (long)(year/365);
			if(y>5){
				ret=10;
			}else{
				ret=1;
			}
		}else{
			
		}
		
		return ret;
	}
	public int getCount()
	{
		return m_vec.size();
	}
	public T getItem(int position)
	{
		return m_vec.get(position);
	}
	public long getItemId(int position)
	{
		return position;
	}
	protected View initView(ViewGroup parent){
		return null;
	}

	protected void setContent(View retV,Object content,int pos){
//		TextView nickname = (TextView) retV.findViewById(R.id.bbs_item_nickname);
//		TextView summary = (TextView) retV.findViewById(R.id.bbs_item_content);
//		TextView subcount = (TextView) retV.findViewById(R.id.bbs_item_subcount);
//		String str=String.format(CommonDefine.getResources(mContext).getString(R.string.bbs_subcount), (String)content.get(XmlNode.Node_subcount));
//		nickname.setText(CommonDefine.getResources(mContext).getString(R.string.bbs_nickname)+(String)content.get(XmlNode.Node_nickname));	
//		summary.setText((String)content.get(XmlNode.Node_content));
//		String istop =(String)content.get(XmlNode.Node_istop); 
//		if(istop!=null && istop.equals("1")){
//			summary.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.headtopic_1, 0);
//		}else{
//			summary.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
//		}
//		if(Long.valueOf((String)content.get(XmlNode.Node_parentmsgid))==0){
//			subcount.setVisibility(View.VISIBLE);
//			subcount.setText(str);
//		}else{
//			subcount.setVisibility(View.GONE);
//		}
	}
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View retV = convertView; 
 
		try{
			if(retV==null){
				retV=initView(parent);
				
			}
			setContent(retV,m_vec.get(position),position);

		}catch(NullPointerException e){
		}
	
		return retV;
	}

//	public void UpdateData(long curlevel, ArrayList<HashMap<String,Object>> contentList) {
//		// TODO Auto-generated method stub
//		m_vec.clear();
//		m_curlevel = curlevel;
//		m_vec = contentList;
//		
//		notifyDataSetChanged();
//		
//	}


}